#!/bin/bash

for username in "$@"
do
	if id $username &>/dev/null;then
		#产生随机密码
		u_passwd=$(echo $RANDOM|sha256sum |cut -c1-10)
		#给用户设置密码
                echo "$username:$u_passwd"|chpasswd
		#保存用户名和密码到文件里
		echo "username:$username   password:$u_passwd" >>user_password.txt
	else
		useradd $username
		#产生随机密码
		u_passwd=$(mkpasswd -l 10 -s 2)
		#给用户设置密码
                echo "$username:$u_passwd"|chpasswd
		#保存用户名和密码到文件里
		echo "username:$username   password:$u_passwd" >>user_password.txt
	fi
done
